package vista;
import java.awt.event.ActionListener;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class vCompra extends javax.swing.JFrame {
	private JLabel lblnum;
	private JLabel lblDetalle;
	private JButton btnremover;
	private JLabel lblunidad;
	private JButton btnbuscar;
	private JButton btnsalir;
	private JButton btncancelar;
	private JButton btnguardar;
	private JSeparator spbton;
	private JLabel lblbs1;
	private JTextField txttotal;
	private JLabel lbltotal;
	private JScrollPane scdetalle;
	private JButton btnincluir;
	private JLabel lblnumero;
	private JSeparator spdetalle;
	private JTextField txtcodigo;
	private JLabel lblcodigo;
	private JComboBox cmbunidad;
	private JLabel lblbs;
	private JTextField txtcantidad;
	private JLabel lblcantidad;
	private JTextField txtcosto;
	private JLabel lblcosto;
	private JTextField txtingrediente;
	private JLabel lblingrediente;
	private JTable detallecompra;
	private vDetalleCompraMT modelo;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				vCompra inst = new vCompra();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public vCompra() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setBackground(new java.awt.Color(255,255,255));
			getContentPane().setLayout(null);
			this.setTitle("Registrar Compra");
			{
				lblnum = new JLabel();
				getContentPane().add(lblnum);
				lblnum.setText("Numero de Compra : ");
				lblnum.setBounds(22, 22, 124, 16);
			}
			{
				lblnumero = new JLabel();
				getContentPane().add(lblnumero);
				lblnumero.setText("1");
				lblnumero.setBounds(165, 22, 10, 16);
			}
			{
				lblingrediente = new JLabel();
				getContentPane().add(lblingrediente);
				lblingrediente.setText("Ingrediente :    ");
				lblingrediente.setBounds(239, 93, 93, 16);
			}
			{
				txtingrediente = new JTextField();
				getContentPane().add(txtingrediente);
				txtingrediente.setBounds(319, 92, 91, 19);
				txtingrediente.setEditable(false);
			}
			{
				lblcosto = new JLabel();
				getContentPane().add(lblcosto);
				lblcosto.setText("Precio : ");
				lblcosto.setBounds(22, 130, 48, 16);
			}
			{
				txtcosto = new JTextField();
				getContentPane().add(txtcosto);
				txtcosto.setBounds(74, 128, 31, 20);
				txtcosto.setEditable(false);
			}
			{
				lblcantidad = new JLabel();
				getContentPane().add(lblcantidad);
				lblcantidad.setText("Cantidad : ");
				lblcantidad.setBounds(154, 130, 63, 16);
			}
			{
				txtcantidad = new JTextField();
				getContentPane().add(txtcantidad);
				txtcantidad.setBounds(222, 129, 35, 19);
				txtcantidad.setEditable(false);
			}
			{
				lblbs = new JLabel();
				getContentPane().add(lblbs);
				lblbs.setText("Bs.");
				lblbs.setBounds(111, 132, 23, 13);
			}
			{
				ComboBoxModel cmbunidadModel = 
					new DefaultComboBoxModel(
							new String[] { "Kg", "Unidad" });
				cmbunidad = new JComboBox();
				getContentPane().add(cmbunidad);
				cmbunidad.setModel(cmbunidadModel);
				cmbunidad.setBounds(289, 127, 70, 23);
			}
			{
				lblcodigo = new JLabel();
				getContentPane().add(lblcodigo);
				lblcodigo.setText("Codigo  :");
				lblcodigo.setBounds(22, 92, 70, 17);
			}
			{
				txtcodigo = new JTextField();
				getContentPane().add(txtcodigo);
				txtcodigo.setBounds(90, 92, 46, 18);
			}
			{
				spdetalle = new JSeparator();
				getContentPane().add(spdetalle);
				spdetalle.setBounds(0, 54, 553, 18);
			}
			{
				lblDetalle = new JLabel();
				getContentPane().add(lblDetalle);
				lblDetalle.setText("Detalle Compra");
				lblDetalle.setBounds(175, 61, 184, 16);
				lblDetalle.setFont(new java.awt.Font("Segoe UI",1,16));
			}
			{
				btnincluir = new JButton();
				getContentPane().add(btnincluir);
				btnincluir.setText("Incluir");
				btnincluir.setBounds(454, 173, 85, 23);
			}
			{
				btnremover = new JButton();
				getContentPane().add(btnremover);
				btnremover.setText("Remover");
				btnremover.setBounds(456, 216, 85, 23);
			}
			{
				scdetalle = new JScrollPane();
				getContentPane().add(scdetalle);
				scdetalle.setBounds(22, 173, 415, 124);
				{
					detallecompra= new JTable();
					scdetalle.setViewportView(detallecompra);
					modelo = new vDetalleCompraMT();
					detallecompra.setModel(modelo);
				}
			}
			{
				lbltotal = new JLabel();
				getContentPane().add(lbltotal);
				lbltotal.setText("Total :");
				lbltotal.setBounds(394, 309, 42, 16);
			}
			{
				txttotal = new JTextField();
				getContentPane().add(txttotal);
				txttotal.setBounds(442, 307, 44, 20);
				txttotal.setEditable(false);
			}
			{
				lblbs1 = new JLabel();
				getContentPane().add(lblbs1);
				lblbs1.setText("Bs.");
				lblbs1.setBounds(492, 309, 29, 16);
			}
			{
				spbton = new JSeparator();
				getContentPane().add(spbton);
				spbton.setBounds(0, 356, 553, 10);
			}
			{
				btnguardar = new JButton();
				getContentPane().add(btnguardar);
				btnguardar.setText("Guardar");
				btnguardar.setBounds(34, 392, 95, 23);
			}
			{
				btncancelar = new JButton();
				getContentPane().add(btncancelar);
				btncancelar.setText("Cancelar");
				btncancelar.setBounds(166, 392, 100, 23);
			}
			{
				btnsalir = new JButton();
				getContentPane().add(btnsalir);
				btnsalir.setText("Salir");
				btnsalir.setBounds(419, 392, 64, 23);
			}
			{
				btnbuscar = new JButton();
				getContentPane().add(btnbuscar);
				btnbuscar.setText("Buscar");
				btnbuscar.setBounds(148, 90, 85, 23);
			}
			{
				lblunidad = new JLabel();
				getContentPane().add(lblunidad);
				lblunidad.setText("Unidad");
				lblunidad.setBounds(288, 130, 49, 16);
				lblunidad.setVisible(false);
			}
			pack();
			this.setSize(568, 494);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	public vDetalleCompraMT getmodelo()
	{
		return modelo;
	}
	public int getnumero()
	{
		return Integer.parseInt(lblnumero.getText());
	}
	public void setNumero(int Numero)
	{
		Numero=Numero+1;
		lblnumero.setText(String.valueOf(Numero));
	}
	public String gecodigo()
	{
		return txtcodigo.getText();
	}
	
	public String getingrediente()
	{
		return txtingrediente.getText();
	}
	public double getprecio()
	{
		return Double.parseDouble(txtcosto.getText());
	}
	public double getcantidad()
	{
		return Double.parseDouble(txtcantidad.getText());
	}
	public String getunidad()
	{
		return cmbunidad.getSelectedItem().toString();
	}
	public Double gettotal()
	{
		return Double.parseDouble(txttotal.getText());
	}
	public void setTotal(double acumulador)
	{
	    txttotal.setText(String.valueOf(acumulador));
	}
	public void addListener(ActionListener actionListener)
	{
		btnguardar.addActionListener(actionListener);
		btncancelar.addActionListener(actionListener);
		btnsalir.addActionListener(actionListener);
		cmbunidad.addActionListener(actionListener);
		btnincluir.addActionListener(actionListener);
		btnremover.addActionListener(actionListener);
	    btnbuscar.addActionListener(actionListener);
    }
	public JLabel getlblunidad()
	{
		return lblunidad;
	}
	public JComboBox getcmbunidad()
	{
		return cmbunidad;
	}
	public JTextField gettxtcodigo()
	{
		return txtcodigo;
	}
	public JTextField gettxtingrediente()
	{
		return txtingrediente;
	}
	public JTextField gettxtcosto()
	{
		return txtcosto;
	}
	public JTextField gettxtcantidad()
	{
		return txtcantidad;
	}
	public int Posicion()
	{
		return detallecompra.getSelectedRow();
	}
	public void Limpiar()
	{
		txtcodigo.setText("");
		txtingrediente.setText("");
		txtcosto.setText("");
		txttotal.setText("");
		txtcantidad.setText("");		
	}
	public void Limpiar2()
	{
		txtcodigo.setText("");
		txtingrediente.setText("");
		txtcosto.setText("");
		txtcantidad.setText("");		
	}
	public void Mensaje(String mensaje)
	{
		JOptionPane.showMessageDialog(this,mensaje);
		
	}
}
